package sg.edu.nus.iss.cerberus.model;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.ui.wizards.NewTypeWizardPage.ImportsManager;

public class TestGenerationData {

	private ArrayList<MethodTestData> methodTestData;
	//priyanka- bug fix, fixture data doesnot need to be an arraylist, its class level datastructure
	private FixtureData fixtureData;
	private CClass cut,testClass;
	private IType type, classUnderTest;
	private ImportsManager imports;
	private boolean isAddcomment;
	private String typeName;
	
	public CClass getTestClass() {
		return testClass;
	}

	public void setTestClass(CClass testClass) {
		this.testClass = testClass;
	}
	private IPackageFragment packageFragment;
	
	public TestGenerationData(){
		
		methodTestData=null;
		fixtureData=null;
		cut=null;
		testClass=null;
		type=null; classUnderTest=null;
		imports=null;
		isAddcomment=false;
		typeName=null;
		
	}
		
	public void setType(IType type) {
		this.type = type;
	}

	public void setClassUnderTest(IType classUnderTest) {
		this.classUnderTest = classUnderTest;
	}

	public void setImports(ImportsManager imports) {
		this.imports = imports;
	}

	public void setAddcomment(boolean isAddcomment) {
		this.isAddcomment = isAddcomment;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public void setPackageFragment(IPackageFragment packageFragment) {
		this.packageFragment = packageFragment;
	}

	public TestGenerationData(ArrayList<MethodTestData> methodTestData,
			FixtureData fixtureData, CClass cut, IType type,
			IType classUnderTest, ImportsManager imports, boolean isAddcomment,
			String typeName, IPackageFragment packageFragment) {
		super();
		this.methodTestData = methodTestData;
		this.fixtureData = fixtureData;
		this.cut = cut;
		this.type = type;
		this.classUnderTest = classUnderTest;
		this.imports = imports;
		this.isAddcomment = isAddcomment;
		this.typeName = typeName;
		this.packageFragment = packageFragment;
	
	}
	
	public TestGenerationData(ArrayList<MethodTestData> methodTestData,
			FixtureData fixtureData, CClass cut) {
		super();
		this.methodTestData = methodTestData;
		this.fixtureData = fixtureData;
		this.cut = cut;
	}
	public ArrayList<MethodTestData> getMethodTestData() {
		return methodTestData;
	}
	public void setMethodTestData(ArrayList<MethodTestData> methodTestData) {
		this.methodTestData = methodTestData;
	}
	public FixtureData getFixtureData() {
		return fixtureData;
	}
	public void setFixtureData(FixtureData fixtureData) {
		this.fixtureData = fixtureData;
	}
	public CClass getCut() {
		return cut;
	}
	public void setCut(CClass cut) {
		this.cut = cut;
	}
	
	public MethodTestData getMethodTestData(String className,String methodName){
		if(className.equals(cut.getClassName())){
			Iterator<MethodTestData> iter = methodTestData.iterator(); 
			while(iter.hasNext()){
				MethodTestData testData = iter.next();
				if(methodName.equals(testData.getName())){
					return testData;
				}
			}
		}
		return null;
	}
	
	public MethodTestData getMethodTestData(String methodName,ArrayList<String> params){
		
		Iterator<MethodTestData> iter = methodTestData.iterator(); 
		while(iter.hasNext()){
			MethodTestData testData = iter.next();
			if(methodName.equals(testData.getName())){
				ArrayList<String> temp  =testData.getSignature();
				for(int i=0;i< Math.min(params.size(),temp.size());i++)
				{	if(params.get(i).trim().contains(temp.get(i).trim()))
					{
						if(i==params.size()-1){return testData;}
					}					
				}
				
				
			}
		}
	
	return null;
}
	
	public MethodTestData getMethodTestData(String methodName){
	
			Iterator<MethodTestData> iter = methodTestData.iterator(); 
			while(iter.hasNext()){
				MethodTestData testData = iter.next();
				if(methodName.equals(testData.getName())){
					return testData;
				}
			}
		
		return null;
	}
	
	
	
	public IType getType(){
		return type;
	}
	public IType getClassUnderTest(){
		return classUnderTest;
	}
	public ImportsManager getImportsManager(){
		return imports;
	}
	public boolean getIsAdComment(){
		return isAddcomment;
	}
	public String getTypeName(){
		return typeName;
	}
	public IPackageFragment getPackageFragment(){
		return  packageFragment;
	}
	
}
